package com.tencent.mm.ui.widget;

import com.tencent.mm.sdk.platformtools.ad;

import java.lang.ref.WeakReference;
import java.util.LinkedList;

public class WidgetH {
    private static LinkedList<WeakReference<a>> FQw = new LinkedList<>();
    private static final String TAG = "MicroMsg.SwipeBackHelper";

    public interface a {
        boolean forceRemoveNoMatchOnPath();

        void onSettle(boolean z, int i);

        void onSwipe(float f);
    }

    public static void a(a aVar) {
        ad.d(TAG, "pushCallback size %d, %s", FQw.size(), aVar.toString());
        FQw.add(0, new WeakReference<>(aVar));
    }

    public static void bJ(float f) {
        if (FQw.size() <= 0) {
            return;
        }
        a aVar = (a) ((WeakReference) FQw.get(0)).get();
        if (aVar == null) {
            return;
        }
        aVar.onSwipe(f);
    }

    public static boolean b(a aVar) {
        if (aVar == null) {
            return true;
        }
        ad.d(TAG, "popCallback size %d, %s", FQw.size(), aVar.toString());
        LinkedList<Integer> linkedList = new LinkedList<>();
        for (int i = 0; i < FQw.size(); i++) {
            if (aVar == ((WeakReference) FQw.get(i)).get()) {
                FQw.remove(i);
                break;
            }
            linkedList.add(0, i);
        }
        if (aVar.forceRemoveNoMatchOnPath() || linkedList.size() != 0) {
            for (Object o : linkedList) {
                FQw.remove(((Integer) o).intValue());
            }
            return linkedList.isEmpty();
        }
        return false;
    }

    public static void T(boolean z, int i) {
        if (FQw.size() <= 0) {
            ad.w(TAG, "notifySettle callback stack empty!, open:%B, speed:%d", z, i);
            return;
        }
        a aVar = (a) ((WeakReference) FQw.get(0)).get();
        if (aVar == null) {
            ad.w(TAG, "notifySettle null, open:%B, speed:%d", z, i);
            return;
        }
        aVar.onSettle(z, i);
        ad.v(TAG, "notifySettle, open:%B speed:%d callback:%s", z, i, aVar);
    }
}
